<?php
include 'functions.php';
$id = $_GET['id'];
$mimeheader['sprite'] = 'application/octet-stream';
$mimeheader['jpg'] = 'image/jpeg';
$mimeheader['jpeg'] = 'image/jpeg';
$mimeheader['png'] = 'image/png';
$mimeheader['bmp'] = 'image/pmp';
$mimeheader['mp3'] = 'audio/mpeg';
$q = "SELECT * FROM res_resources WHERE id=$id";
if (!$resdap_mod_features) {
	$q .= ' AND hide=0';
}
resdap_connect();
$result = mysql_query($q);
if($row = mysql_fetch_array($result)) {
	$filename=preg_replace('/[^a-zA-Z0-9]/', '', $row['title']).'.'.$row['ext'];
	header("Content-disposition: attachment; filename=$filename");
	header('Content-type: '.$mimeheader[$row['ext']]);
	readfile('../files/resources/'.$row['id'].'.'.$row['ext']);	  		
} else {
	echo 'An error occured: your download is unavailable.';
}
resdap_disconnect();
?>